# coding=utf-8
from ml.knn.dating.read_data import *
from ml.knn.KNN import *

ho_rate = 0.10
dating_data_mat, dating_date_labels = file2matrix("datingTestSet2.txt")
norm_mat, ranges, min_val = auto_norm(dating_data_mat)

m = norm_mat.shape[0]
test_num = int(m * ho_rate)
error_count = 0

for i in range(test_num):
    classifier_res = classify0(norm_mat[i, :], norm_mat[test_num:m, :],
                               dating_date_labels[test_num:m], 3)
    print("the classifier came back with: %d, the real answer is: %d" %
          (classifier_res, dating_date_labels[i]))

    if classifier_res != dating_date_labels[i]:
        error_count += 1.0
print("the total error rate: %f" % (error_count / float(test_num)))
